home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14542 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.nask.org.pl!usenet
  2. From: flssoft@blue.maloka.waw.pl (Grzegorz (FLS))
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: HELP with child windows
  5. Date: Mon, 01 Apr 1996 00:53:30 GMT
  6. Organization: Research and Academic Computer Network
  7. Message-ID: <4jn5of$s1a@bilbo.nask.org.pl>
  8. References: <4jeqas$g5p@news.bellglobal.com>
  9. NNTP-Posting-Host: s111.maloka.waw.pl
  10. X-Newsreader: Forte Free Agent v0.46
  11.  
  12. bogdanfl@aei.ca (Bogdan  Florescu) wrote:
  13.  
  14. >In MS Visual C++ v 1.5, I need to do this: I have two edit boxes. When
  15. >I select "New" from the menu, it should set  a blinking cursor in the
  16. >box that I want, so I can start immediately entering data, without
  17. >selecting first the box with the mouse. How do I do this? How do I
  18. >transfer the control from one window to another?
  19.  
  20. >Thanks.
  21.  
  22. Use a focus. I suppose that the edit boxes are in dialog window. In
  23. this way, you have to have IDs for them (like ID_EDIT_FIRST,
  24. ID_EDIT_SECOND). You have two ways to do that. The first one is to use
  25. <CWnd::GetDlgItem()> function to obtain a CWnd* pointer of neede
  26. control. This is example in a dialog method:
  27.     ...
  28.  CWnd* pItemWnd = GetDlgItem( ID_EDIT_FIRST ) ;
  29.  
  30.     if ( pItemWnd != NULL )
  31.         pItemWnd->SetFocus() ;
  32.     ...
  33.  
  34. or
  35.     GetDlgItem( ID_EDIT_FIRST )->SetFocus() ;
  36.  
  37. if you are sure that you have an ID_EDIT_FIRST control.
  38.  
  39. The second one is to use MFC Class Wizard's feature. You can add a
  40. variable attached to the control.
  41. Launch Wizard,
  42. select Member Variables,
  43. select ID_EDIT_FIRST line,
  44. click Add Variable...,
  45. write a variable name like m_c_edit_first,
  46. in Property combo select Control line,
  47. click OK
  48.  
  49. Note that in second solution you cannot attach two variables to the
  50. same control (one for value, second for control). Of course Wizard
  51. does not mind if you done it, but you will have some problems after
  52. that.
  53. Anyway, the first solution will work always (?), and I suggest you to
  54. use it.
  55.  
  56. Regards,
  57.  
  58. Grzegorz
  59.  
  60.  
  61.